package com.eightywork.life.adapter;

import java.util.List;


import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.eightywork.life.R;
import com.eightywork.life.adapter.MyEventListAdapter.ViewHolder;
import com.eightywork.life.image.MyImageGetter;
import com.eightywork.life.model.Comment;
import com.eightywork.life.util.FuncUtil;

public class ReplyListAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private int mResource = R.layout.item_reply;
	private  List<Comment> list;
	private Context context;

	public ReplyListAdapter(Context context, List<Comment> list) {
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.list = list;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		final Comment comment = list.get(position);
		if (convertView == null) {
			holder = new ViewHolder();
			convertView =  mInflater.inflate(mResource, parent, false);
			holder.message =  (TextView) convertView.findViewById(R.id.message);
			holder.time = (TextView) convertView.findViewById(R.id.time);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder)convertView.getTag();
		}
		holder.message.setText(Html.fromHtml(comment.getAuthorname() + " : "
				+ comment.getMessage(), new MyImageGetter(context), null));
		holder.time.setText(FuncUtil.timeToText(Long.valueOf(comment.getDateline()) * 1000));
//		View layout = convertView;
//		if (layout == null) {
//			layout = mInflater.inflate(mResource, parent, false);
//		}
//		Comment object = getItem(position);
//		TextView message = (TextView) layout.findViewById(R.id.message);
//		message.setText(Html.fromHtml(object.getAuthorname() + " : "
//				+ object.getMessage(), new MyImageGetter(getContext()), null));
//		TextView time = (TextView) layout.findViewById(R.id.time);
//		time.setText(FuncUtil.timeToText(Long.valueOf(object.getDateline()) * 1000));
//		return layout;
		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return (list!=null) ? list.size():0;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	public final class ViewHolder {
	    private TextView message;
	    private TextView time;
	}
}
